
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../generated/l10n.dart';
import '../../l10n/LanguageProvider.dart';
import '../face_page.dart';


class LanguageSetting extends StatelessWidget {
  const LanguageSetting({super.key});

  @override
  Widget build(BuildContext context) {
    final languageProvider = Provider.of<LanguageProvider>(context);
    final currentLocale = languageProvider.currentLocale;
    final locales = [Locale('en', 'US'),Locale('zh', 'CN'),];
    final localeDisplayNames = ['English','中文',];

    return Scaffold(
      appBar: AppBar(
        title: Text(S.of(context).setting_language_appTitle),
      ),
      body: Center(
        child: Wrap(
          children: <Widget>[
            DropdownButton<Locale>(
              hint: Text(S.of(context).title),
              isDense: true,
              iconSize: 24,
              iconEnabledColor: Colors.grey[600],
              value: currentLocale,
              items: locales.map((locale) {
                return DropdownMenuItem<Locale>(
                  value: locale,
                  child: Text(localeDisplayNames[locales.indexOf(locale)]),
                );
              }).toList(),
              onChanged: (Locale? newLocale) {
                if (newLocale != null && newLocale != languageProvider.currentLocale) {
                  languageProvider.changeLocale(newLocale);
                }
              },
            ),
          ],
        ),
      ),
    );
  }
}